package com.sky.factory;

import java.util.Scanner;

/**
 * Created by Frank Lau on 2017/5/26 0026.
 */
public class calculator_1_1 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("請輸入數字A: ");
        String A = scanner.nextLine();
        System.out.println("請輸入運算符(+ - * /): ");
        String B = scanner.nextLine();
        System.out.println("請輸入數字B: ");
        String C = scanner.nextLine();

        String D;
        switch (B) {
            case "+":
                D = String.valueOf(Double.parseDouble(A) + Double.parseDouble(C));
                System.out.println(D);
                break;
            case "-":
                D = String.valueOf(Double.parseDouble(A) - Double.parseDouble(C));
                System.out.println(D);
                break;
            case "*":
                D = String.valueOf(Double.parseDouble(A) * Double.parseDouble(C));
                System.out.println(D);
                break;
            case "/":
                if (C != "0") {
                    D = String.valueOf(Double.parseDouble(A) / Double.parseDouble(C));
                    System.out.println(D);
                }
                else {
                    System.out.println("除數不能為0.");
                }
                break;
        }
    }
}
